package com.nbsaas.boot.order.ext.handle;

import com.nbsaas.boot.order.api.apis.OrderApi;
import com.nbsaas.boot.order.api.domain.request.OrderRequest;
import com.nbsaas.boot.order.api.domain.response.OrderResponse;
import com.nbsaas.boot.pay.api.domain.response.PaymentResponse;
import com.nbsaas.boot.pay.ext.apis.PayHandler;
import com.nbsaas.boot.rest.filter.Filter;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class OrderPayHandler implements PayHandler {

    @Resource
    private OrderApi orderApi;


    @Override
    public void pay(PaymentResponse payment) {
        OrderResponse order = orderApi.oneData(Filter.eq("id", payment.getBussId()));
        if (order == null) {
            return;
        }
        OrderRequest request = new OrderRequest();
        request.setId(order.getId());
        request.setPaymentStatus(1);
        request.setState(2);
        request.setPayNo(payment.getBussNo());
        orderApi.update(request);
    }
}
